<?php

namespace App\Http\Controllers\admin;

use App\Dao\CategoryDao;
use App\Dao\ProjectDao;
use App\Exceptions\SysExceptions;
use App\Services\Code;

class ProjectController extends BaseController
{
    public function projects(){
        if(getIsHasPage()){
            return  Code::message('',200,ProjectDao::get_projects_page(request()->all()));
        }

        return view('admin.projects.projects',[
        ]);
    }





    /**
     * @throws SysExceptions
     */
    public function add_project(){
        if(isPost()){
            ProjectDao::add_project(request()->all());
            return Code::message('',200);
        }
        $categorys = CategoryDao::get_datas();
        return view('admin.projects.add',[
            'categorys'=>$categorys
        ]);
    }


    public function edit_project(){
        if(isPost()){
            ProjectDao::edit_project(request()->all());
            return Code::message('',200);
        }
        $categorys = CategoryDao::get_datas();

        $info = ProjectDao::getOne(request()->all());
        return view('admin.projects.edit',[
            'info'=>$info,
            'categorys'=>$categorys
        ]);
    }



    public function del_project(){
            $params = request()->all();
            ProjectDao::del_project($params);
            return Code::message('删除成功',200);
    }


    public function set_skus(){
        if(isPost()){
            ProjectDao::setSkus(request()->all());
            return Code::message('添加成功',200);
        }
        $yanse = ProjectDao::getSkus(request('project_id'),1);
        $sizes = ProjectDao::getSkus(request('project_id'),2);
        return view('admin.projects.set_skus',[
            'colors'=>$yanse,
            'sizes'=>$sizes,
            'project_id'=>request('project_id')
        ]);
    }




}
